package com.fr.report.write;

import com.fr.base.Inter;
import com.fr.base.StringUtils;
import com.fr.base.XMLable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.cellElement.Formula;
import com.fr.report.io.xml.ReportXMLUtils;

public class ValueVerifier
  implements XMLable
{
  public static final String XML_TAG = "VV";
  public static final int SUCCESS = 0;
  public static final int ERROR = 1;
  public static final int WARNING = 2;
  private Formula formula = null;
  private String message = "";
  private int type = 0;

  public ValueVerifier()
  {
  }

  public ValueVerifier(String paramString1, String paramString2)
  {
    setFormula(new Formula(paramString1));
    setMessage(paramString2);
  }

  public Formula getFormula()
  {
    return this.formula;
  }

  public void setFormula(Formula paramFormula)
  {
    this.formula = paramFormula;
  }

  public int getType()
  {
    return this.type;
  }

  public void setType(int paramInt)
  {
    this.type = paramInt;
  }

  public String getMessage()
  {
    return this.message;
  }

  public void setMessage(String paramString)
  {
    this.message = paramString;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if ("O".equals(str))
      {
        Object localObject = ReportXMLUtils.readObject(paramXMLableReader);
        if (localObject instanceof Formula)
          setFormula((Formula)localObject);
      }
      else if ("Message".equals(str))
      {
        setMessage(paramXMLableReader.getElementValue());
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("VV");
    if (this.formula != null)
    {
      ReportXMLUtils.writeObject(paramXMLPrintWriter, this.formula);
      if (!(StringUtils.isEmpty(this.message)))
        paramXMLPrintWriter.startTAG("Message").textNode(this.message).end();
    }
    paramXMLPrintWriter.end();
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("[");
    if (getType() == 0)
    {
      localStringBuffer.append(Inter.getLocText("Success"));
      localStringBuffer.append("]");
      localStringBuffer.append(" ");
      localStringBuffer.append(Inter.getLocText("Expression"));
      localStringBuffer.append(": ");
      localStringBuffer.append(this.formula);
      return localStringBuffer.toString();
    }
    if (getType() == 1)
      localStringBuffer.append(Inter.getLocText("Error"));
    else if (getType() == 2)
      localStringBuffer.append(Inter.getLocText("Warning"));
    localStringBuffer.append("]");
    localStringBuffer.append(" ");
    localStringBuffer.append(Inter.getLocText("Expression"));
    localStringBuffer.append(": ");
    localStringBuffer.append(this.formula);
    localStringBuffer.append("  ");
    localStringBuffer.append(Inter.getLocText("Message"));
    localStringBuffer.append(": ");
    localStringBuffer.append(this.message);
    return localStringBuffer.toString();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ValueVerifier localValueVerifier = (ValueVerifier)super.clone();
    localValueVerifier.setFormula((Formula)this.formula.clone());
    return localValueVerifier;
  }
}